package cn.vcjf.washcar.userInfo.controller;


import cn.vcjf.washcar.common.web.TableResult;
import cn.vcjf.washcar.userInfo.entity.UserCar;
import cn.vcjf.washcar.userInfo.service.UserCarService;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/**
 * <p>
 * 用户汽车表 前端控制器
 * </p>
 *
 * @author zhengzihang
 * @since 2018-07-18
 */
@Controller
@RequestMapping("/userInfo/userCar")
public class UserCarController {
	@Resource
	private UserCarService userCarService;

	@RequestMapping("/addUserCar")
	@ResponseBody
	public TableResult addUserCar(UserCar userCar) {
		userCar.preInsert();
		boolean b = userCarService.insert(userCar);
		return TableResult.Result(b);
	}

	@RequestMapping("/updateUserCar")
	@ResponseBody
	public TableResult updateUserCar(UserCar userCar) {
		userCar.preUpdate();
		boolean b = userCarService.updateById(userCar);
		return TableResult.Result(b);
	}

	@RequestMapping("/findUserCarOne")
	@ResponseBody
	public TableResult findUserCarOne(UserCar userCar) {

		EntityWrapper<UserCar> wrapper = userCar.getQueryWrapper();

		UserCar result = userCarService.selectOne(wrapper);

		return TableResult.Result(result);
	}

	@RequestMapping("/findUserCarList")
	@ResponseBody
	public TableResult findUserCarList(UserCar userCar) {

		EntityWrapper<UserCar> wrapper = userCar.getQueryWrapper();

		Page<UserCar> page = userCar.getPageInfo();
		wrapper.orderBy("createTime", false);
		page = userCarService.selectPage(page, wrapper);

		return TableResult.Result(page);

	}

	@RequestMapping("/deleteUserCarByIds")
	@ResponseBody
	public TableResult deleteUserCarByIds(String... ids) {
		List<String> list = Arrays.asList(ids);
		boolean b = userCarService.deleteBatchIds(list);
		return TableResult.Result(b);
	}
}
